import constant from '@/store/constant.js'

export default {
	get(url,callback){
		var obj={
			"status":false,
			"data":null,
			"msg":"",
			};
		uni.request({
			
			url:constant.baseUrl+url,
			method:"GET",
			header: {
			        'auth': uni.getStorageSync("token") 
			    },
			success: (res) => {	
				if(res.data.code==0){
					obj.status=true;
					obj.data=res.data.result
					
				}else{
					obj.msg=res.data.message;
				}
				callback(obj);
			},
			fail:function(err){
				obj.msg=err;
				callback(obj);
			}
		})
	},
	post(url,data,callback){
		var obj={
			"status":false,
			"data":null,
			"msg":"",
			};
			
		uni.request({
			
			url:constant.baseUrl+url,
			method:"POST",
			data:data,
			header: {
			        'auth': uni.getStorageSync("token") 
			    },
			success: (res) => {
				
				if(res.data.code==0){
					obj.status=true;
					obj.data=res.data.result

				}else{
					obj.msg=res.data.message;
				}
				callback(obj);
					
			},
			fail:function(err){
				obj.msg=err;
				callback(obj);
			}
		})
	},
	image(filePath,callback){
		uni.uploadFile({
			url: constant.baseUrl+'/api/upload/uploadFile', 
			filePath: filePath,
			name: 'file',
			
			success: (result) => {
				let data =JSON.parse(result.data);
				
				callback(data);
			
			}
		});
	},
	video(filePath,callback){
		uni.uploadFile({
			url: constant.baseUrl+'/api/upload/uploadVideo', 
			filePath: filePath,
			name: 'file',
			
			success: (result) => {
				let data =JSON.parse(result.data);
				
				callback(data);
			
			}
		});
	},

}